var wait = 60;//短信时间
var _false = false;
$(function () {
    $(".submit").click(function () {
        submit();//点击提交
    })
    $('.code').bind("click",function () {
        if(!_false){
            SendCode(); //发送验证码
        }
    });
})
//点击提交
function submit() {
    if($(".userName").val()==""){
        YDUI.dialog.toast('昵称不能为空','none',function(){});
        return;
    }if($(".phone").val()==""){
        YDUI.dialog.toast('手机号不能为空','none',function(){});
        return;
    }if($(".phone").val().length != 11){
        YDUI.dialog.toast('手机号码格式不正确','none',function(){});
        return;
    }if($(".code-auth").val()==""){
        YDUI.dialog.toast('验证码不能为空','none',function(){});
        return;
    }if($(".pwd").val()==""){
        YDUI.dialog.toast('密码不能为空','none',function(){});
        return;
    }if($(".pwd").val().length >16 || $(".pwd").val().length < 6){
        YDUI.dialog.toast('密码不符合规范，请重新输入','none',function(){});
        return;
    }if($(".pwd-affirm").val() != $(".pwd").val()){
        YDUI.dialog.toast('两次密码不一致，请重新输入','none',function(){});
        return;
    }else {
        submitBtn();//提交
    }
}
//提交
function submitBtn() {
    $.ajax({
        type: "get",
        cache:true,
        url:"http://115.159.106.174:8080/vanoo/weixin/worker_edit.do?token=123&vercode="+$('.code-auth').val()+"&fphone="+$('.phone').val()+"&wxpwd="+$('.pwd').val()+"&fwkrname="+$('.userName').val()+"",
        data: '',
        dataType: "json",
        beforeSend:function () {
        },
        complete:function () {
        },
        success: function(result){
            console.log(result);
            if(result.msg == 'success'){
                YDUI.dialog.toast('修改成功','success',function(){});
                setTimeout(function () {
                    window.location.href = 'login.html';
                },1000)
            }else {
                YDUI.dialog.toast(result.msg,'error',function(){});
            }
            
        },error : function(e) {
            YDUI.dialog.toast(e.msg,'error',function(){});
        }
    });
}

//发送验证码
function SendCode() {
    if ($(".phone").val() == "") {
        YDUI.dialog.toast('请先输入手机号码','none',function(){});
    } else if ($(".phone").val().length != 11) {
        YDUI.dialog.toast('手机号码格式不正确','none',function(){});
    } else {
        $.ajax({
            type: "get",
            cache:true,
            url:"http://115.159.106.174:8080/vanoo/weixin/phonecode.do?phone="+$('.phone').val()+"&token=123",
            data: '',
            dataType: "json",
            beforeSend:function () {
            },
            complete:function () {
            },
            success: function(result){
               // console.log(result);
                if(result.msg == "success"){
                    YDUI.dialog.toast('发送成功','success',function(){});
                    SendTime(".code");
                }else {
                    YDUI.dialog.toast(result.msg,'error',function(){});
                }

            },error : function(e) {
                YDUI.dialog.toast(e.msg,'error',function(){});
            }
        });

    }
}

function SendTime(parameter){
    var Send = $(""+parameter+"");
    if (wait == 0) {
        Send.html("发送验证码");
        wait = 60;
        _false  = false;
    } else {
        Send.html("重新发送(" + wait + ")s");
        wait--;
        _false = true;
        setTimeout(function() {
            SendTime(parameter);
        },1000);
    }
}